package com.example.controller;

import com.example.entity.InsuredPerson;
import com.example.service.InsuredPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/insuredPerson")
public class InsuredPersonController {
    
    @Autowired
    private InsuredPersonService insuredPersonService;

    // 创建参保人员
    @PostMapping("/register")
    public String registerInsuredPerson(@RequestParam int insuredpersonid) {
        InsuredPerson person = new InsuredPerson();
        person.setInsuredpersonid(insuredpersonid);
        insuredPersonService.registerInsuredPerson(person);
        return "参保人员注册成功";
    }

    // 查询参保人员
    @GetMapping("/get/{id}")
    public InsuredPerson getInsuredPerson(@PathVariable int id) {
        return insuredPersonService.getInsuredPersonById(id);
    }

    // 查询所有参保人员
    @GetMapping("/all")
    public List<InsuredPerson> getAllInsuredPersons() {
        return insuredPersonService.getAllInsuredPersons();
    }

    // 更新参保人员信息
    @PutMapping("/update")
    public String updateInsuredPerson(@RequestBody InsuredPerson person) {
        insuredPersonService.updateInsuredPerson(person);
        return "参保人员信息更新成功";
    }

    // 删除参保人员
    @DeleteMapping("/delete/{id}")
    public String deleteInsuredPerson(@PathVariable int id) {
        insuredPersonService.deleteInsuredPerson(id);
        return "参保人员删除成功";
    }
}
